import {
    isUndefined
} from 'lodash-es'
import {
    GETDATA,
    H,
    getField,
    I
} from '../utils/R'


export default {
    namespace: 'leftBottom',
    state: {},
    subscriptions: {
        setup({
            dispatch,
            history
        }) {
            history.listen(({
                pathname
            }) => {
                if (pathname == '/two') {
                    dispatch({
                        type: 'getDatas'
                    })
                }
            })
        }
    },
    effects: {
        * getDatas({
            params
        }, {
            call,
            put
        }) {
            let {
                data
            } = yield call(GETDATA, H, {}, {
                zy: isUndefined(params) ? "02" : params
            })

            let payload = {
                list: getField(data, 'nj'),
                axisData: getField(data, 'sums'),
            }

            let {
                data: N
            } = yield call(GETDATA, I)
            payload.zyh = N
            yield put({
                type: 'setData',
                payload
            })
        }
    },
    reducers: {
        setData(state, action) {
            return action.payload
        }
    }
}